package org.oslims.client.view.impl;

import org.oslims.client.uicomponents.editbox.EditAnalysisBox;
import org.oslims.client.view.AnalysisEditorView;
import org.oslims.domain.Analysis;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class AnalysisEditorViewImpl extends BaseViewImpl implements AnalysisEditorView {

	final Button addAnalysisButton = new Button("Add Analysis");
	final CellTable<Analysis> analysisTable = new CellTable<Analysis>();
	Integer defaultPageSize = 18;
	final SimplePager<Analysis> pager = new SimplePager<Analysis>(analysisTable);

	EditAnalysisBox editAnalysisBox = new EditAnalysisBox();

	public AnalysisEditorViewImpl() {

		DockLayoutPanel content = new DockLayoutPanel(Unit.PCT);
		content.setStyleName("mainContent");

		VerticalPanel headerPanel = new VerticalPanel();

		Label header = new Label("Analysis Management");
		header.setStyleName("viewHeader");

		headerPanel.add(header);
		content.addNorth(headerPanel, 5);

		VerticalPanel footerPanel = new VerticalPanel();
		footerPanel.add(pager);
		footerPanel.add(addAnalysisButton);
		content.addSouth(footerPanel, 10);

		ScrollPanel tablePanel = new ScrollPanel();
		tablePanel.add(analysisTable);

		content.add(tablePanel);

		initWidget(content);
	}

	@Override
	public HasClickHandlers getAddAnalysisButton() {
		return addAnalysisButton;
	}

	@Override
	public EditAnalysisBox getEditAnalysisBox() {
		return editAnalysisBox;
	}

	@Override
	public CellTable<Analysis> getTable() {
		return analysisTable;
	}

	@Override
	public Integer getDefaultPageSize() {
		return defaultPageSize;
	}

	@Override
	public SimplePager<Analysis> getPager() {
		return pager;
	}

	@Override
	public Boolean confirmEdit(String message) {
		return Window.confirm(message);
	}

}
